/*
ID: pallab81
PROG:
LANG: C++
*/

//"I have not failed, I have just found 10000 ways that won't work.

#include <iostream>
#include <algorithm>
#include <vector>
#include <sstream>
#include <fstream>
#include <string>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <iomanip>

#include <ctime>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <climits>
#include <cstdlib>

using namespace std;

#define VI vector< int >
#define CI( x ) scanf("%d",&x)
#define CL( x ) scanf("%lld",&x)
#define CD( x ) scanf("%lf",&x )
#define foR(i1,st,ed) for(int i1 = st,j1 = ed ; i1 < j1 ; ++i1 )
#define fo(i,ed) foR( i , 0 , ed )
#define foE(i,st,ed) foR( i , st , ed+1 )
#define foit(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
#define bip( X ) sleep( X )
#define Int long long
#define pb push_back
#define SZ(X) (int)(X).size()
#define LN(X) (int)(X).length()
#define mk make_pair
#define f first
#define s second
#define SET( ARRAY , VALUE ) memset( ARRAY , VALUE , sizeof(ARRAY) )
#define line puts("")

template<class T1>
inline void debug(T1 _x) {
    cout<<_x<<'\n';
}
template<class T1, class T2>
inline void debug(T1 _x,T2 _y) {
    cout<<_x<<' '<<_y<<'\n';
}
template<class T1, class T2, class T3>
inline void debug(T1 _x,T2 _y,T3 _z) {
    cout<<_x<<' '<<_y<<' '<<_z<<'\n';
}
template<class T1, class T2, class T3, class T4>
inline void debug(T1 _x,T2 _y,T3 _z,T4 _zz) {
    cout<<_x<<' '<<_y<<' '<<_z<<' '<<_zz<<'\n';
}
template< class T1>
inline void debug(T1 _array,int _size) {
    cout<<"[";
    for (int i=0; i<_size; ++i) {
        cout<<' '<<_array[i];
    }
    puts(" ]");
}

class DoubleRoshambo {
public:
    int maxScore(vector <string> A, vector <string> E);
};
const int MAXN = (50+50)+5;
int cap[MAXN][MAXN], flow[MAXN][MAXN], cost[MAXN][MAXN];
int n, sink, source, total_cost;

inline int cf(int i, int j) {
    if (flow[j][i]) return flow[j][i];
    else return cap[i][j] - flow[i][j];
}

inline int costf(int i, int j) {
    if (flow[j][i]) return -cost[j][i];
    else return cost[i][j];
}

inline void pushf(int i, int j, int x) {
    total_cost += costf(i, j) * x;
    if (flow[j][i]) flow[j][i] -= x;
    else flow[i][j] += x;
}
int dist[MAXN], prev[MAXN];
bool reach[MAXN];
inline int augment(void) {
    bool changed;

    SET(reach,0);
    reach[source] = changed = true;
    dist[source] = 0;
    while (changed) {
        changed = false;
        fo(i,n) {
            if (reach[i]) {
                fo (j,n) {
                    if (cf(i, j)) {
                        if (!reach[j] || dist[i] + costf(i, j) < dist[j]) {
                            reach[j] = changed = true;
                            dist[j] = dist[i] + costf(i, j);
                            prev[j] = i;
                        }
                    }
                }
            }
        }
    }
    if (!reach[sink]) return 0;
    for (int i = sink; i != source; i = prev[i]) pushf(prev[i], i, 1);
    return 1;
}

int mcmf(void) {
    int ret, x;
    SET(flow,0);
    ret = total_cost = 0;
    while ((x = augment())) ret += x;
    return ret;
}
inline bool win(char a, char b) {
    if(a=='R'&&b=='S')return true;
    if(a=='S'&&b=='P')return true;
    if(a=='P'&&b=='R')return true;
    return false;
}
inline int point(string a, string b) {
    if(win(a[1],b[1])&&win(a[0],b[0]))return 2;
    if( win(a[1],b[1])&&(a[0]==b[0]) )return 1;
    return 0;
}
inline void build_flow_network( vector<string> &A, vector<string> &E) {
    SET(cap,0);
    SET(cost,0);

    n=SZ(A);
    //nodes to nodes
    fo(i,n) {
        fo(j,n) {
            int tmp=point(A[i],E[j]);
            cap[i][n+j]=1;
            cost[i][n+j]=tmp*(-1);

        }
    }

    source=n+n;
    sink=source+1;
    //source to all nodes
    fo(i,n) {
        cap[source][i]=1;
        cost[source][i]=0;
    }
    //all nodes to sink
    fo(j,n) {
        cap[n+j][sink]=1;
        cost[n+j][sink]=0;
    }
    //total nodes
    n = sink+1;

}
int DoubleRoshambo :: maxScore(vector <string> A, vector <string> E) {
    build_flow_network(A,E);
    int ret = mcmf();
    //debug("RESULT = ",ret,total_cost);

    return abs(total_cost);
}
// BEGIN KAWIGIEDIT TESTING
// Generated by KawigiEdit 2.1.8 (beta) modified by pivanof
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool KawigiEdit_RunTest(int testNum, vector <string> p0, vector <string> p1, bool hasAnswer, int p2) {
    cout << "Test " << testNum << ": [" << "{";
    for (int i = 0; int(p0.size()) > i; ++i) {
        if (i > 0) {
            cout << ",";
        }
        cout << "\"" << p0[i] << "\"";
    }
    cout << "}" << "," << "{";
    for (int i = 0; int(p1.size()) > i; ++i) {
        if (i > 0) {
            cout << ",";
        }
        cout << "\"" << p1[i] << "\"";
    }
    cout << "}";
    cout << "]" << endl;
    DoubleRoshambo *obj;
    int answer;
    obj = new DoubleRoshambo();
    clock_t startTime = clock();
    answer = obj->maxScore(p0, p1);
    clock_t endTime = clock();
    delete obj;
    bool res;
    res = true;
    cout << "Time: " << double(endTime - startTime) / CLOCKS_PER_SEC << " seconds" << endl;
    if (hasAnswer) {
        cout << "Desired answer:" << endl;
        cout << "\t" << p2 << endl;
    }
    cout << "Your answer:" << endl;
    cout << "\t" << answer << endl;
    if (hasAnswer) {
        res = answer == p2;
    }
    if (!res) {
        cout << "DOESN'T MATCH!!!!" << endl;
    } else if (double(endTime - startTime) / CLOCKS_PER_SEC >= 2) {
        cout << "FAIL the timeout" << endl;
        res = false;
    } else if (hasAnswer) {
        cout << "Match :-)" << endl;
    } else {
        cout << "OK, but is it right?" << endl;
    }
    cout << "" << endl;
    return res;
}
int main() {
    bool all_right;
    all_right = true;

    vector <string> p0;
    vector <string> p1;
    int p2;

    {
        // ----- test 0 -----
        string t0[] = {"RR"};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        string t1[] = {"SS"};
        p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
        p2 = 2;
        all_right = KawigiEdit_RunTest(0, p0, p1, true, p2) && all_right;
        // ------------------
    }

    {
        // ----- test 1 -----
        string t0[] = {"SR","PP"};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        string t1[] = {"PR","RS"};
        p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
        p2 = 1;
        all_right = KawigiEdit_RunTest(1, p0, p1, true, p2) && all_right;
        // ------------------
    }

    {
        // ----- test 2 -----
        string t0[] = {"PP","PP","PP","PP"};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        string t1[] = {"RR","PR","SS","SP"};
        p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
        p2 = 3;
        all_right = KawigiEdit_RunTest(2, p0, p1, true, p2) && all_right;
        // ------------------
    }

    {
        // ----- test 3 -----
        string t0[] = {"PS","RS","PP","SP","RR","SS","SP"};
        p0.assign(t0, t0 + sizeof(t0) / sizeof(t0[0]));
        string t1[] = {"RP","SP","RR","SR","RS","SP","SS"};
        p1.assign(t1, t1 + sizeof(t1) / sizeof(t1[0]));
        p2 = 10;
        all_right = KawigiEdit_RunTest(3, p0, p1, true, p2) && all_right;
        // ------------------
    }

    if (all_right) {
        cout << "You're a stud (at least on the example cases)!" << endl;
    } else {
        cout << "Some of the test cases had errors." << endl;
    }
    return 0;
}
// END KAWIGIEDIT TESTING


//Powered by KawigiEdit 2.1.8 (beta) modified by pivanof!
